﻿using Dal;
using Interfaces;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using TestStack.BDDfy;
using TestStack.BDDfy.Configuration;
using TestStack.BDDfy.Core;
using TestStack.BDDfy.Scanners.StepScanners.Fluent;

namespace Tests.Dal
{
    [TestFixture]
    [Category("DAL")]
    [Story(
        Title = "Getting Locations from the dal",
        AsA = "As a person playing the adventure",
        IWant = "I Want to get locations from the Dal",
        SoThat = "So that I have somewhere to stand in the game")]
    class GetLocations
    {
        IDal _dal = null;
        List<Location> _locations = null;

        public void GivenADalFor(IDal dal)
        {
            _dal = dal;
        }

        public void WhenTheDalGetsTheLocations()
        {
            _locations = _dal.GetLocations();
        }

        public void ThenTheLocationsNumber(int count)
        {
            Assert.AreEqual(count, _locations.Count());
        }

        public void AndTheFirstLocationHasATitleOf(string title)
        {
            Assert.AreEqual(title, _locations.First().Title);
        }

        public void AndTheFirstLocationIsDescribedAs(string description)
        {
            Assert.AreEqual(description, _locations.First().Body);
        }

        public void ThenTheFistLocationHasCommandsThatNumber(int count)
        {
            Assert.AreEqual(count, _locations.First().Commands.Count());
        }

        public void AndTheFirstCommandIs(string commandText)
        {
            Assert.AreEqual(commandText, _locations.First().Commands.First().CommandText);
        }

        public void AndTheFirstCommandWillGoToDestinationId(int goToDestinationId)
        {
            Assert.AreEqual(goToDestinationId, _locations.First().Commands.First().GoToDestinationId);
        }


        [Test]
        public void LoadAllTheGoldAdventureLocations()
        {
            new GetLocations()
                .Given(dt => dt.GivenADalFor(new TheGoldAventure()))
                .When(dt => dt.WhenTheDalGetsTheLocations())
                .Then(dt => dt.ThenTheLocationsNumber(47))
                .And(dt => dt.AndTheFirstLocationHasATitleOf("Grotty Old Abandoned Gold Mine"))
                .And(dt => dt.AndTheFirstLocationIsDescribedAs(string.Format("This is where your adventure begins.{0}Fugly the dwarf rubs his hands together.{0}*We only have 10 more gold pieces to steal before we can buy this beautiful old mine! Now are you sure you're okay carrying this Bag of Gold?* He passes you a heafty bag of Gold pieces.{0}*Time to be off.* He walks out the Mine entrance.\r", Environment.NewLine)))
                .And(dt => dt.ThenTheFistLocationHasCommandsThatNumber(1))
                .And(dt => dt.AndTheFirstCommandIs("East"))
                .And(dt => dt.AndTheFirstCommandWillGoToDestinationId(2))
                .BDDfy();

        }

        [Test]
        public void GetLocationsJson()
        {
            var locations = new TheGoldAventure().GetJsonLocations();

            var jsn = new JavaScriptSerializer().Serialize(locations);


            Assert.AreEqual(47,locations.Count());
            Assert.AreNotEqual("Howdy", jsn);


        }
    }
}
